using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Data.Model;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Admin_Admin_JXC_CheckAccountAoucher : Admin, IRequiresSessionState
{
	protected Literal ltrTitle;
	protected HtmlTable table_item;
	protected TextBox txtSearchBeginDate;
	protected TextBox txtSearchEndDate;
	protected TextBox txtSearchInfoNumber;
	protected Button btnSearch;
	protected GridView gvManage;
	protected Literal ltrPagePanel;
	protected Panel pnlManage;
	protected Panel pnlDetail;
	private string linkHead = "";
	private string beforeUrl = "Admin_JXC_CheckAccountAoucher.aspx?MenuID=1&MenuName=财务管理&FileName=凭证查找";
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.admin.CheckAdminPower(43))
			{
				base.WriteLog("Modidy", Language.GetAdminMsg("Log/Access", "0"), "Admin_JXC_CheckAccountAoucher");
				base.WriteRightErrMsg();
			}
			this.BindData();
		}
	}
	protected string GetQuery()
	{
		string text = " where 1=1 ";
		string text2 = Fetch.Get("BeginTime");
		if (!string.IsNullOrEmpty(text2))
		{
			this.txtSearchBeginDate.Text = text2;
		}
		else
		{
			text2 = this.txtSearchBeginDate.Text;
		}
		if (!string.IsNullOrEmpty(text2))
		{
			text = text + " and DATEDIFF(DD, InputDate,'" + text2 + "')<=0";
			this.linkHead = this.linkHead + "&BeginTime=" + text2;
		}
		string text3 = Fetch.Get("EndTime");
		if (!string.IsNullOrEmpty(text3))
		{
			this.txtSearchEndDate.Text = text3;
		}
		else
		{
			text3 = this.txtSearchEndDate.Text;
		}
		if (!string.IsNullOrEmpty(text3))
		{
			if (!string.IsNullOrEmpty(text2))
			{
				if (Convert.ToDateTime(text2) > Convert.ToDateTime(text3))
				{
					this.WriteErrMsg("", Language.Get("Common/DateTimeErr"), "");
				}
			}
			text = text + "and DATEDIFF(DD, InputDate,'" + text3 + "')>=0";
			this.linkHead = this.linkHead + "&EndTime=" + text3;
		}
		string text4 = Fetch.Get("AccountANumber");
		if (!string.IsNullOrEmpty(text4))
		{
			this.txtSearchInfoNumber.Text = text4;
		}
		else
		{
			text4 = this.txtSearchInfoNumber.Text;
		}
		if (!string.IsNullOrEmpty(text4))
		{
			text = text + " and AccountANumber like '%" + text4 + "%'";
			this.linkHead = this.linkHead + "&AccountANumber=" + text4;
		}
		return text;
	}
	private string GetQueryByOrder()
	{
		return "order by AccountAoucherID desc";
	}
	public void BindData()
	{
		string query = this.GetQuery();
		string queryByOrder = this.GetQueryByOrder();
		int num = this.gvManage.PageIndex;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		DataTable listAccountAoucherItemSubjcet = BLLInstance.BllAccountAoucher.GetListAccountAoucherItemSubjcet(query);
		DataTable dataTable = BLLInstance.BllAccountAoucher.GetNewDataSet(listAccountAoucherItemSubjcet, true).Tables[0];
		int pageSize = this.gvManage.PageSize;
		int count = dataTable.Rows.Count;
		this.gvManage.DataSource = CurrPageLinks.instance.GetPagedTable(dataTable, num, pageSize);
		this.gvManage.DataBind();
		string url = this.beforeUrl + this.linkHead + "&pageindex";
		this.ltrPagePanel.Text = CurrPageLinks.instance.CurrPageLinkStr(num, pageSize, count, "条记录&nbsp;每页" + pageSize + "条记录&nbsp;", url, true);
	}
	protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.gvManage.PageIndex = e.NewPageIndex;
		this.BindData();
	}
	protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected void Button_Command(object sender, CommandEventArgs e)
	{
		string comeUrl = this.beforeUrl + this.linkHead + "&pageindex";
		string commandName = e.CommandName;
		if (commandName == "DelInfo")
		{
			string value = e.CommandArgument.ToString();
			HoWave.Data.Model.AccountAoucher model = BLLInstance.BllAccountAoucher.GetModel(Convert.ToInt32(value));
			if (model != null)
			{
				DataTable dataTable = BLLInstance.BllAccountAoucherItem.GetList("AccountAoucherID=" + Convert.ToInt32(value)).Tables[0];
				for (int i = 0; i < dataTable.Rows.Count; i++)
				{
					int accountAItemID = Convert.ToInt32(dataTable.Rows[i]["AccountAItemID"].ToString());
					BLLInstance.BllAccountAoucherItem.Delete(accountAItemID);
				}
				bool flag = BLLInstance.BllAccountAoucher.Delete(Convert.ToInt32(value));
				if (flag)
				{
					this.WriteErrMsg("", "删除凭证信息成功！", comeUrl);
				}
			}
		}
	}
	protected void btnSearch_Click(object sender, EventArgs e)
	{
		this.BindData();
	}
}
